home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmiSoft / Util / Misc / Reportplus.lha / reportplus / source / f7.c < prev    next >
C/C++ Source or Header  |  2003-02-14  |  25KB  |  689 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <libraries/gadtools.h>
  6. #include <dos/dosextens.h>
  7. #include <graphics/gfx.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/graphics_protos.h>
  14.  
  15. #define ALL_REACTION_CLASSES
  16. #define ALL_REACTION_MACROS
  17. #include <reaction/reaction.h>
  18.  
  19. #include <ctype.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "rp.h"
  23.  
  24. #define AMIGA 0
  25. #define MAC   1
  26. #define IBM   2
  27.  
  28. // from rp.c
  29. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  30. IMPORT ABOOL               fillwindows, stop;
  31. IMPORT SBYTE               page;
  32. IMPORT SWORD               y;
  33. IMPORT TEXT                asldir[PATHNAMEFIELD + 1];
  34. IMPORT ULONG               fillcolour;
  35. IMPORT struct NewGadget    Gadget;
  36. IMPORT struct Window*      MainWindowPtr;
  37. IMPORT struct Screen*      ScreenPtr;
  38. IMPORT struct IconBase*    IconBase;
  39. IMPORT struct SharedStruct shared;
  40. IMPORT Object*             WinObject[FUNCTIONS + 1];
  41. IMPORT struct Menu*        MenuPtr;
  42.  
  43. MODULE struct
  44. {   ULONG detabulate, unwrap, source, dest, tabsize;
  45.     TEXT  pathname[PATHNAMEFIELD + 1];
  46. } eol =
  47. {   FALSE, FALSE, IBM, AMIGA, 8, ""
  48. };
  49.  
  50. AGLOBAL struct Gadget* eol_gadgets[GIDS_7 + 1];
  51.  
  52. MODULE STRPTR EOLOptions[4] =
  53. {   (STRPTR) "LF (Amiga)",
  54.     (STRPTR) "CR (Macintosh)",
  55.     (STRPTR) "CR+LF (IBM-PC)",
  56.     NULL
  57. };
  58.  
  59. MODULE ABOOL spaceeol(TEXT nextchar);
  60.  
  61. AGLOBAL void eol1(void)
  62. {   struct Hook Hook7Struct;
  63.  
  64.     InitHook(&Hook7Struct, Hook7Func, NULL);
  65.  
  66.     /* Create the window object. */
  67.     lockscreen();
  68.     if (!(WinObject[7] =          NewObject(WINDOW_GetClass(), NULL,
  69.     // window
  70.     WA_PubScreen,                 ScreenPtr,
  71.     WA_ScreenTitle,               "Report+",
  72.     WA_Title,                     "Report+: EOL/Tab Converter",
  73.     WA_Activate,                  TRUE,
  74.     WA_DepthGadget,               TRUE,
  75.     WA_DragBar,                   TRUE,
  76.     WA_CloseGadget,               TRUE,
  77.     WA_SizeGadget,                TRUE,
  78.     WA_IDCMP,                     IDCMP_RAWKEY,
  79.     WINDOW_IDCMPHook,             &Hook7Struct,
  80.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  81.     WINDOW_MenuStrip,             MenuPtr,
  82.     WINDOW_Position,              WPOS_CENTERSCREEN,
  83.     WINDOW_ParentGroup,           eol_gadgets[GID_7_LY1] =
  84.                                   NewObject(LAYOUT_GetClass(), NULL,
  85.         // root-layout
  86.         LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  87.         LAYOUT_SpaceOuter,        TRUE,
  88.         LAYOUT_DeferLayout,       TRUE,
  89.         LAYOUT_AddChild,
  90.         NewObject
  91.         (   LAYOUT_GetClass(),    NULL,
  92.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  93.             LAYOUT_VertAlignment, LALIGN_CENTER,
  94.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  95.             LAYOUT_BevelStyle,    BVS_NONE,
  96.             LAYOUT_AddChild,
  97.             NewObject
  98.             (   LAYOUT_GetClass(),    NULL,
  99.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  100.                 LAYOUT_SpaceOuter,    TRUE,
  101.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  102.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  103.                 LAYOUT_BevelStyle,    BVS_FIELD,
  104.                 LAYOUT_AddImage,          NewObject
  105.                 (   LABEL_GetClass(),     NULL,
  106.                     LABEL_Text,           "_Source:",
  107.                     LABEL_Justification,  LJ_CENTER,
  108.                 TAG_END),
  109.                 CHILD_WeightedHeight,     0,
  110.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA1] =
  111.                 NewObject
  112.                 (   RADIOBUTTON_GetClass(),NULL,
  113.                     GA_ID,                GID_7_RA1,
  114.                     GA_RelVerify,         TRUE,
  115.                     GA_Text,              EOLOptions,
  116.                     RADIOBUTTON_Selected, (WORD) eol.source,
  117.                 TAG_END),
  118.             TAG_END),
  119.             CHILD_WeightedWidth,      50,
  120.             LAYOUT_AddChild,
  121.             NewObject
  122.             (   LAYOUT_GetClass(),    NULL,
  123.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  124.                 LAYOUT_SpaceOuter,    TRUE,
  125.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  126.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  127.                 LAYOUT_BevelStyle,    BVS_FIELD,
  128.                 LAYOUT_AddImage,          NewObject
  129.                 (   LABEL_GetClass(),     NULL,
  130.                     LABEL_Text,           "_Destination:",
  131.                     LABEL_Justification,  LJ_CENTER,
  132.                 TAG_END),
  133.                 CHILD_WeightedHeight,     0,
  134.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA2] =
  135.                 NewObject
  136.                 (   RADIOBUTTON_GetClass(),NULL,
  137.                     GA_ID,                GID_7_RA2,
  138.                     GA_RelVerify,         TRUE,
  139.                     GA_Text,              EOLOptions,
  140.                     RADIOBUTTON_Selected, (WORD) eol.dest,
  141.                 TAG_END),
  142.             TAG_END),
  143.             CHILD_WeightedWidth,      50,
  144.         TAG_END),
  145.         LAYOUT_AddChild,
  146.         NewObject
  147.         (   LAYOUT_GetClass(),    NULL,
  148.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  149.             LAYOUT_VertAlignment, LALIGN_CENTER,
  150.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  151.             LAYOUT_BevelStyle,    BVS_NONE,
  152.             LAYOUT_AddChild,          eol_gadgets[GID_7_CB1] =
  153.             NewObject
  154.             (   CHECKBOX_GetClass(),  NULL,
  155.                 GA_ID,                GID_7_CB2,
  156.                 GA_RelVerify,         TRUE,
  157.                 GA_Text,              "C_onvert tabs to spaces?",
  158.                 GA_Selected,          (BOOL) eol.detabulate,
  159.             TAG_END),
  160.             CHILD_WeightedWidth,      0,
  161.             LAYOUT_AddImage,
  162.             NewObject
  163.             (   LABEL_GetClass(),     NULL,
  164.                 LABEL_Text,           "",
  165.             TAG_END),
  166.             CHILD_WeightedWidth,      100,
  167.             LAYOUT_AddImage,
  168.             NewObject
  169.             (   LABEL_GetClass(),     NULL,
  170.                 LABEL_Text,           "_Tab size:",
  171.             TAG_END),
  172.             CHILD_WeightedWidth,      0,
  173.             LAYOUT_AddChild,          eol_gadgets[GID_7_IN1] =
  174.             NewObject
  175.             (   INTEGER_GetClass(),   NULL,
  176.                 GA_ID,                GID_7_IN1,
  177.                 GA_RelVerify,         TRUE,
  178.                 GA_TabCycle,          TRUE,
  179.                 INTEGER_Number,       eol.tabsize,
  180.                 INTEGER_Minimum,      0,
  181.                 INTEGER_Maximum,      99,
  182.                 INTEGER_MinVisible,   2,
  183.             TAG_END),
  184.             CHILD_WeightedWidth,      0,
  185.         TAG_END), 
  186.         CHILD_WeightedHeight,         0,
  187.         LAYOUT_AddChild,              eol_gadgets[GID_7_CB2] =
  188.         NewObject
  189.         (   CHECKBOX_GetClass(),      NULL,
  190.             GA_ID,                    GID_7_CB2,
  191.             GA_RelVerify,             TRUE,
  192.             GA_Text,                  "_Unwrap words?",
  193.             GA_Selected,              (BOOL) eol.unwrap,
  194.         TAG_END),
  195.         CHILD_WeightedHeight,         0,
  196.         LAYOUT_AddChild,
  197.         NewObject
  198.         (   LAYOUT_GetClass(),        NULL,
  199.             LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  200.             LAYOUT_VertAlignment,     LALIGN_CENTER,
  201.             LAYOUT_HorizAlignment,    LALIGN_CENTER,
  202.             LAYOUT_BevelStyle,        BVS_NONE,
  203.             LAYOUT_AddImage,
  204.             NewObject
  205.             (   LABEL_GetClass(),     NULL,
  206.                 LABEL_Text,           "_Pathname(s):",
  207.                 LABEL_Justification,  LJ_LEFT,
  208.             TAG_END),
  209.             LAYOUT_AddChild,          eol_gadgets[GID_7_ST1] =
  210.             NewObject
  211.             (   STRING_GetClass(),    NULL,
  212.                 GA_ID,                GID_7_ST1,
  213.                 GA_RelVerify,         TRUE,
  214.                 STRINGA_TextVal,      eol.pathname,
  215.                 STRINGA_MinVisible,   20,
  216.             TAG_END),
  217.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU1] =
  218.             NewObject
  219.             (   NULL,             "button.gadget",
  220.                 GA_ID,            GID_7_BU1,
  221.                 GA_RelVerify,     TRUE,
  222.                 BUTTON_AutoButton,BAG_POPFILE,
  223.             TAG_END),
  224.             CHILD_WeightedWidth,  0,
  225.         TAG_END),
  226.         CHILD_WeightedHeight,     0,
  227.         LAYOUT_AddChild,          eol_gadgets[GID_7_ST2] =
  228.         NewObject
  229.         (   STRING_GetClass(),    NULL,
  230.             GA_ReadOnly,          TRUE,
  231.             GA_ID,                GID_7_ST2,
  232.             STRINGA_TextVal,      "Ready.",
  233.         TAG_END),
  234.         CHILD_WeightedHeight,     0,
  235.         LAYOUT_AddChild,
  236.         NewObject
  237.         (   LAYOUT_GetClass(),    NULL,
  238.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  239.             LAYOUT_VertAlignment, LALIGN_CENTER,
  240.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  241.             LAYOUT_BevelStyle,    BVS_NONE,
  242.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU3] =
  243.                                   NewObject(NULL, "button.gadget",
  244.                 GA_ID,            GID_7_BU3,
  245.                 GA_RelVerify,     TRUE,
  246.                 GA_Text,          "Pro_cess",
  247.             TAG_END),
  248.             CHILD_WeightedWidth,  50,
  249.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU4] =
  250.                                   NewObject(NULL, "button.gadget",
  251.                 GA_ID,            GID_7_BU4,
  252.                 GA_RelVerify,     TRUE,
  253.                 GA_Text,          "Stop",
  254.                 GA_Disabled,      TRUE,
  255.             TAG_END),
  256.             CHILD_WeightedWidth,  50,
  257.         TAG_END),
  258.         CHILD_WeightedHeight,     0,
  259.     TAG_END)
  260.     )))
  261.     {   rq("Can't create ReAction objects!");
  262.     }
  263.     unlockscreen();
  264.     openwindow();
  265.     ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  266.  
  267.     loop();
  268.     closewindow();
  269. }
  270.  
  271. AGLOBAL void eol_do(void)
  272. {   STRPTR stringptr;
  273.     ABOOL  anyfound;
  274.  
  275.     if (!(GetAttr
  276.     (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  277.     )))
  278.     {   rq("Unsupported inquiry!"); // should never happen
  279.     }
  280.     strcpy(eol.pathname, stringptr);
  281.     if (!(GetAttr
  282.     (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  283.     )))
  284.     {   rq("Unsupported inquiry!"); // should never happen
  285.     }
  286.  
  287.     SetGadgetAttrs
  288.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  289.         GA_Disabled, FALSE,
  290.     TAG_END);
  291.     SetGadgetAttrs
  292.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  293.         GA_Disabled, TRUE,
  294.     TAG_END);
  295.     SetGadgetAttrs
  296.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  297.         GA_Disabled, TRUE,
  298.     TAG_END);
  299.     SetGadgetAttrs
  300.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  301.         GA_Disabled, TRUE,
  302.     TAG_END);
  303.     SetGadgetAttrs
  304.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  305.         GA_Disabled, TRUE,
  306.     TAG_END);
  307.     SetGadgetAttrs
  308.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  309.         GA_Disabled, TRUE,
  310.     TAG_END);
  311.     SetGadgetAttrs
  312.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  313.         GA_Disabled, TRUE,
  314.     TAG_END);
  315.     SetGadgetAttrs
  316.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  317.         GA_Disabled, TRUE,
  318.     TAG_END);
  319.     SetGadgetAttrs
  320.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  321.         GA_Disabled, TRUE,
  322.     TAG_END);
  323.     SetGadgetAttrs
  324.     (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  325.         STRINGA_TextVal, "Resolving wildcards...",
  326.     TAG_END
  327.     );
  328.  
  329.     strcpy(shared.pathname, eol.pathname);
  330.     anyfound = convert(TRUE);
  331.     strcpy(eol.pathname, shared.pathname);
  332.  
  333.     if (!stop)
  334.     {   if (anyfound)
  335.         {   SetGadgetAttrs
  336.             (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  337.                 STRINGA_TextVal, "All done.",
  338.             TAG_END);
  339.         } else
  340.         {   SetGadgetAttrs
  341.             (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  342.                 STRINGA_TextVal, "No matches!",
  343.             TAG_END);
  344.     }   }
  345.     SetGadgetAttrs
  346.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  347.         GA_Disabled, TRUE,
  348.     TAG_END);
  349.     SetGadgetAttrs
  350.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  351.         GA_Disabled, FALSE,
  352.     TAG_END);
  353.     SetGadgetAttrs
  354.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  355.         GA_Disabled, FALSE,
  356.     TAG_END);
  357.     SetGadgetAttrs
  358.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  359.         GA_Disabled, FALSE,
  360.     TAG_END);
  361.     SetGadgetAttrs
  362.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  363.         GA_Disabled, FALSE,
  364.     TAG_END);
  365.     SetGadgetAttrs
  366.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  367.         GA_Disabled, FALSE,
  368.     TAG_END);
  369.     SetGadgetAttrs
  370.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  371.         GA_Disabled, FALSE,
  372.     TAG_END);
  373.     SetGadgetAttrs
  374.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  375.         GA_Disabled, FALSE,
  376.     TAG_END);
  377.     SetGadgetAttrs
  378.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  379.         GA_Disabled, FALSE,
  380.     TAG_END);
  381. }
  382.  
  383. AGLOBAL void eolconvert(ABOOL gui)
  384. {   ULONG                gap, i, j, cursorx = 0;
  385.     ABOOL                ok                 = TRUE;
  386.     struct FileInfoBlock InputInfoBlock;
  387.     UBYTE*               InputBufferPtr; // always use UBYTE not APTR for pointer arithmetic
  388.     BPTR                 FileHandle;
  389.     TEXT                 saystring[PATHNAMEFIELD + 1];
  390.  
  391.     strcpy(saystring, "Converting ");
  392.     strcat(saystring, shared.thisfile);
  393.     strcat(saystring, "...");
  394.     if (gui)
  395.     {   SetGadgetAttrs
  396.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  397.             STRINGA_TextVal, saystring,
  398.         TAG_END);
  399.     } else
  400.     {   Printf("%s", saystring);
  401.         Flush(Output());
  402.     }
  403.  
  404.     if (FileHandle = (BPTR) Lock(shared.thisfile, ACCESS_READ))
  405.     {   if (Examine(FileHandle, &InputInfoBlock))
  406.         {   UnLock(FileHandle);
  407.             // FileHandle = NULL;
  408.             if (InputInfoBlock.fib_DirEntryType == -3) // if a file
  409.             {   // if it is a directory, we would ideally like to convert all
  410.                 // files in that directory. We also should support links.
  411.                 if (InputBufferPtr = AllocMem(InputInfoBlock.fib_Size, MEMF_ANY | MEMF_PUBLIC))
  412.                 {   if (FileHandle = (BPTR) Open(shared.thisfile, MODE_OLDFILE))
  413.                     {   if (Read(FileHandle, InputBufferPtr, InputInfoBlock.fib_Size) != -1)
  414.                         {   Close(FileHandle);
  415.                             if (FileHandle = (BPTR) Open(shared.thisfile, MODE_NEWFILE))
  416.                             {   for (i = 0; i < InputInfoBlock.fib_Size; i++)
  417.                                 {   if (*(InputBufferPtr + i) == LF)
  418.                                     {   if (eol.unwrap && (eol.source == AMIGA || eol.source == IBM) && spaceeol(*(InputBufferPtr + i + 1)))
  419.                                         {   cursorx++;
  420.                                             FPutC(FileHandle, ' ');
  421.                                         } else
  422.                                         {   cursorx = 0;
  423.  
  424.                                             if (eol.source == eol.dest)
  425.                                                 FPutC(FileHandle, LF); // pass it through
  426.                                             elif (eol.source == AMIGA && eol.dest == IBM)
  427.                                             {   FPutC(FileHandle, CR); // add this
  428.                                                 FPutC(FileHandle, LF); // and pass this through
  429.                                             } elif (eol.source == AMIGA && eol.dest == MAC)
  430.                                                 FPutC(FileHandle, CR); // convert from LF to CR
  431.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  432.                                                 FPutC(FileHandle, LF); // pass it through
  433.                                             elif (eol.source == IBM && eol.dest == MAC)
  434.                                                 ; // do nothing
  435.                                             else ; // mac as source: we never expect LFs
  436.                                     }   }
  437.                                     elif (*(InputBufferPtr + i) == CR)
  438.                                     {   if (eol.unwrap && eol.source == MAC && spaceeol(*(InputBufferPtr + i + 1)))
  439.                                         {   cursorx++;
  440.                                             FPutC(FileHandle, ' ');
  441.                                         } else
  442.                                         {   cursorx = 0;
  443.  
  444.                                             if (eol.source == eol.dest)
  445.                                                 FPutC(FileHandle, CR); // pass it through
  446.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  447.                                                 ; // do nothing
  448.                                             elif (eol.source == IBM && eol.dest == MAC)
  449.                                                 FPutC(FileHandle, CR); // pass it through
  450.                                             elif (eol.source == MAC && eol.dest == AMIGA)
  451.                                                 FPutC(FileHandle, LF); // convert from CR to LF
  452.                                             elif (eol.source == MAC && eol.dest == IBM)
  453.                                             {   FPutC(FileHandle, CR); // pass this through
  454.                                                 FPutC(FileHandle, LF); // and add this
  455.                                             } else ; // amiga as source: we never expect CRs
  456.                                     }   }
  457.                                     elif (*(InputBufferPtr + i) == TAB)
  458.                                     {   if (eol.detabulate)
  459.                                         {   gap = (((cursorx / eol.tabsize) + 1) * eol.tabsize) - cursorx;
  460.                                             for (j = 1; j <= gap; j++)
  461.                                                 FPutC(FileHandle, ' ');
  462.                                             cursorx += gap;
  463.                                         } else FPutC(FileHandle, TAB); // no point to cursorx in non-detabulate
  464.                                     } else
  465.                                     {   FPutC(FileHandle, *(InputBufferPtr + i));
  466.                                         cursorx++;
  467.                                 }   }
  468.                                 /* Note that FPutC() returns EOF for errors; this is not currently
  469.                                 checked. */
  470.                                 ok = TRUE;
  471.                                 Close(FileHandle);
  472.                         }   }
  473.                         else
  474.                         {   Close(FileHandle);
  475.                     }   }
  476.                     FreeMem(InputBufferPtr, InputInfoBlock.fib_Size);
  477.         }   }   }
  478.         else
  479.         {   UnLock(FileHandle);
  480.     }   }
  481.  
  482.     if (gui)
  483.     {   if (ok)
  484.             strcat(saystring, "done.");
  485.         else strcat(saystring, "failed!");
  486.  
  487.         SetGadgetAttrs
  488.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  489.             STRINGA_TextVal, saystring,
  490.         TAG_END);
  491.     } else
  492.     {   if (ok)
  493.             Printf("done.\n");
  494.         else Printf("failed!\n");
  495.     }
  496.  
  497.     checkabort(gui);
  498. }
  499.  
  500. AGLOBAL void eol_loop(ULONG gid)
  501. {   STRPTR stringptr;
  502.  
  503.     switch(gid)
  504.     {
  505.     case GID_7_RA1:
  506.         if (!(GetAttr
  507.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA1], (ULONG *) &eol.source
  508.         )))
  509.         {   rq("Unsupported inquiry!"); // should never happen
  510.         }
  511.     break;
  512.     case GID_7_RA2:
  513.         if (!(GetAttr
  514.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA2], (ULONG *) &eol.dest
  515.         )))
  516.         {   rq("Unsupported inquiry!"); // should never happen
  517.         }
  518.     break;
  519.     case GID_7_ST1:
  520.         if (!(GetAttr
  521.         (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  522.         )))
  523.         {   rq("Unsupported inquiry!"); // should never happen
  524.         }
  525.         strcpy(eol.pathname, stringptr);
  526.     break;
  527.     case GID_7_BU1:
  528.         strcpy(shared.pathname, eol.pathname);
  529.         multiasl("~(#?.info)");
  530.         strcpy(eol.pathname, shared.pathname);
  531.         SetGadgetAttrs
  532.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  533.             STRINGA_TextVal, eol.pathname,
  534.             TAG_END
  535.         );
  536.     break;
  537.     case GID_7_BU3:
  538.         eol_do();
  539.     break;
  540.     case GID_7_CB1:
  541.         if (!(GetAttr
  542.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  543.         )))
  544.         {   rq("Unsupported inquiry!"); // should never happen
  545.         }
  546.     break;
  547.     case GID_7_CB2:
  548.         if (!(GetAttr
  549.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  550.         )))
  551.         {   rq("Unsupported inquiry!"); // should never happen
  552.         }
  553.     break;
  554.     case GID_7_IN1:
  555.         if (!(GetAttr
  556.         (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  557.         )))
  558.         {   rq("Unsupported inquiry!"); // should never happen
  559.         }
  560.     break;
  561.     default:
  562.     break;
  563. }   }
  564.  
  565. MODULE ABOOL spaceeol(TEXT nextchar)
  566. {   if
  567.     (   nextchar == ' '
  568.      || nextchar == TAB
  569.      || nextchar == LF
  570.      || nextchar == CR
  571.     )
  572.     {   return(FALSE);
  573.     } else return(TRUE);
  574. }
  575.  
  576. AGLOBAL void eol_die(void)
  577. {   IOBuffer[1] = (UBYTE) eol.source;
  578.     IOBuffer[2] = (UBYTE) eol.dest;
  579.     IOBuffer[3] = (UBYTE) eol.detabulate;
  580.     IOBuffer[4] = (UBYTE) eol.tabsize;
  581.     IOBuffer[5] = (UBYTE) eol.unwrap;
  582. }
  583.  
  584. AGLOBAL void eol_config(void)
  585. {   eol.source     = (ULONG) IOBuffer[1];
  586.     eol.dest       = (ULONG) IOBuffer[2];
  587.     eol.detabulate = (ULONG) IOBuffer[3];
  588.     eol.tabsize    = (ULONG) IOBuffer[4];
  589.     eol.unwrap     = (ULONG) IOBuffer[5];
  590. }
  591.  
  592. AGLOBAL ULONG Hook7Func(struct Hook *h, VOID *o, VOID *msg)
  593. {   /* "When the hook is called, the data argument points to the 
  594.     window object and message argument to the IntuiMessage." */
  595.  
  596.     UWORD code, qual;
  597.  
  598.     geta4(); // wait till here before doing anything
  599.  
  600.     code = ((struct IntuiMessage *) msg)->Code;
  601.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  602.  
  603.     switch(code)
  604.     {
  605.     case SCAN_HELP:
  606.         helpabout();
  607.     break;
  608.     case SCAN_ESCAPE:
  609.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  610.         {   cleanexit(EXIT_SUCCESS);
  611.         } else page = 0;
  612.     break;
  613.     case SCAN_D:
  614.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  615.         {   if (eol.dest < 2)
  616.                 eol.dest++;
  617.             else eol.dest = 0;
  618.         } else
  619.         {   if (eol.dest > 0)
  620.                 eol.dest--;
  621.             else eol.dest = 2;
  622.         }
  623.         SetGadgetAttrs
  624.         (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  625.             RADIOBUTTON_Selected, eol.dest,
  626.         TAG_END);
  627.         // we must explicitly refresh
  628.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA2], MainWindowPtr, NULL);
  629.     break;
  630.     case SCAN_O:
  631.         // the gadget is handled automatically by the system, all we need
  632.         // to do is update our internal record of the state of the gadget
  633.         if (!(GetAttr
  634.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  635.         )))
  636.         {   rq("Unsupported inquiry!"); // should never happen
  637.         }
  638.     break;
  639.     case SCAN_P:
  640.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  641.     break;
  642.     case SCAN_S:
  643.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  644.         {   if (eol.source < 2)
  645.                 eol.source++;
  646.             else eol.source = 0;
  647.         } else
  648.         {   if (eol.source > 0)
  649.                 eol.source--;
  650.             else eol.source = 2;
  651.         }
  652.         SetGadgetAttrs
  653.         (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  654.             RADIOBUTTON_Selected, eol.source,
  655.         TAG_END);
  656.  
  657.         // we must explicitly refresh
  658.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA1], MainWindowPtr, NULL);
  659.     break;
  660.     case SCAN_T:
  661.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_IN1]);
  662.     break;
  663.     case SCAN_U:
  664.         // the gadget is handled automatically by the system, all we need
  665.         // to do is update our internal record of the state of the gadget
  666.         if (!(GetAttr
  667.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  668.         )))
  669.         {   rq("Unsupported inquiry!"); // should never happen
  670.         }
  671.     break;
  672.     case SCAN_PERIOD:
  673.         strcpy(shared.pathname, eol.pathname);
  674.         multiasl("~(#?.info)");
  675.         strcpy(eol.pathname, shared.pathname);
  676.         SetGadgetAttrs
  677.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  678.             STRINGA_TextVal, eol.pathname,
  679.         TAG_END);
  680.     break;
  681.     default:
  682.     break;
  683.     }
  684.  
  685.     return(1);
  686. }
  687.  
  688.  
  689.